<ul id='listaMenu' class='filetree'>
</ul>

<script>
	function goTo(controller, action, title){
		$('#mainPanel').load('procesador.php?controller='+controller+'&action='+ action);
		$('#dashboard').html('Dashboard: '+ title)
	};
	
	$(document).ready(function () {
		$.ajax({ 
			async: false, 
			type: "POST", 
			url: "procesador.php?controller=home&action=getMenu", 
			data: {}, 
			dataType: "json", 
			cache: false, 
			success: function(data){
				
				if(data[0].lev1=='')
				{
					var sTxt="<b>Importante:</b><br>";
					sTxt+="Ud. No tiene un Rol definido en esta aplicación, por favor contactese con el Administrador<br>";
					$("#listaMenu").append(sTxt);
				}else{
					var ctr = data[0].controller.toLowerCase();
					var act = data[0].recurso;
					var file = data[0].lev3;
					var folder = data[0].lev2;
					ctr = ctr.split("controller");
					var auxCtrl = folder;
					var strMenu = '';
					strMenu+= '<li class="closed"><span class="folder">'+folder+'</span>';
					strMenu+= '<ul>';
					strMenu+= '<li onclick=\'goTo(\"'+ctr[0]+'", "'+act+'", "'+file+'")\'>';
					strMenu+= '<span class="file pointer">'+file+'</span>';
					strMenu+= '</li>';
					for(var i=1; i<data.length; i++){
						ctr = data[i].controller.toLowerCase();
						ctr = ctr.split("controller");
						act = data[i].recurso;
						file = data[i].lev3;
						folder = data[i].lev2;
						if(auxCtrl != folder){
							strMenu+= '</ul>';
							strMenu+= '</li>';
							strMenu+= '<li class="closed"><span class="folder">'+folder+'</span>';
							strMenu+= '<ul>';
						}
						strMenu+= '<li onclick=\'goTo("'+ctr[0]+'", "'+act+'", "'+file+'")\'>';
						strMenu+= '<span class="file pointer">'+file+'</span>';
						strMenu+= '</li>';
						auxCtrl = folder;
					}
					strMenu+= '</ul>';
					strMenu+= '</li>';
					$("#listaMenu").append(strMenu);
				}
			}
		});
		$("#listaMenu").treeview();
	});

</script>
